#!/usr/bin/python

#
# xrsh.py: XML-RPC shell
#

import sys;
import xmlrpclib;
import readline;

(host, port, path) = ('', '', '');

if len(sys.argv) > 1:
	host = sys.argv[1];
if len(sys.argv) > 2:
	port = sys.argv[2];
if len(sys.argv) > 3:
	path = sys.argv[3];

if (not host):
	host = 'localhost';
if (not port):
	port = '80';
if (not path):
	path = '';

server = xmlrpclib.ServerProxy('http://' + host + ':' + port + '/' + path);

while (True):
	try:
		next = raw_input("xrsh> ");
	except EOFError:
		print;
		break;

	next = 'server.'+next;
	try:
		print eval(next);
	except Exception, e:
		print("Error: %s" % e);
